package com.itcast.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import reactor.core.publisher.Mono;

/**
 * @author feng js
 */
@Configuration
@Slf4j
public class GloblFilterConfig {

    @Bean
    @Order(1)
    public GlobalFilter globalFilter1() {
        return ((exchange,chain)->{
            log.info("pre1");
            return chain.filter(exchange).then(Mono.fromRunnable(()->{
                log.info("post1");
            }));
        });
    }
    @Bean
    @Order(2)
    public GlobalFilter globalFilter2() {
        return ((exchange,chain)->{
            log.info("pre2");
            return chain.filter(exchange).then(Mono.fromRunnable(()->{
                log.info("post2");
            }));
        });
    }
}
